<template>
  <view id="content">
    <view style="height: 1rpx;margin-top: 50rpx;"></view>
    <view class="item_area">
      <view class="item_view">
        <view class="input_tips">旧密码：</view>
        <view class="input_view">
          <input type="password" class="input_txt" v-model="oldPassword"/>
        </view>
      </view>
    </view>
    <view class="item_area">
      <view class="item_view">
        <view class="input_tips">新密码：</view>
        <view class="input_view">
          <input type="password" class="input_txt" v-model="newPassword1"
                 placeholder="请输入新密码(6-12位数字与字母组合)"/>
        </view>
      </view>
    </view>
    <view class="item_area">
      <view class="item_view">
        <view class="input_tips">确认新密码：</view>
        <view class="input_view">
          <input type="password" class="input_txt" v-model="newPassword2" placeholder="请再次输入密码"/>
        </view>
      </view>
    </view>
    <view style="color: red;margin-left: 50rpx;">{{ tips }}</view>
    <view style="display: flex;justify-content: center;margin-top: 100rpx;">
      <button @click="submit" class="submit">确认</button>
    </view>
  </view>
</template>

<script>
import request from '../../utils/request.js'
import {
  checkLogin
} from '../../utils/common.js'

export default {
  data() {
    return {
      showOverlay: false, // 控制遮罩层显示的变量,
      curUser: {
        'nickName': '游客'
      },
      proxyShow: true,
      dsType: false,
      cyType: false,
      gfType: false,
      ykType: true,
      userImg: '',
      oldPassword: '',
      newPassword1: '',
      newPassword2: '',
      tips: ''
    }
  },
  onShow() {
    var _this = this;
    // 不做强制登录校验
    // if (checkLogin()) {
    // 	_this.userImg = uni.getStorageSync('userImg');
    // 	_this.getUserInfo();
    // }
  },
  onShareAppMessage(res) {
    let pages = getCurrentPages(); //获取当前页面栈的信息
    let currentPage = pages[pages.length - 1]; //获取到当前页面栈中最后一个页面的索引
      if (res.from === 'button') {// 来自页面内分享按钮
        console.log(res.target)
      }
      return {
        title: '逐金污师丨成人情趣甄选好物',
        path: currentPage.route + `?id=${this.id}&share=${this.share}` //后面是路径上要传递的参数
      }
    },
	onShareTimeline(res) {
	  let pages = getCurrentPages(); //获取当前页面栈的信息
	  let currentPage = pages[pages.length - 1]; //获取到当前页面栈中最后一个页面的索引
	    if (res.from === 'button') {// 来自页面内分享按钮
	      console.log(res.target)
	    }
	    return {
	      title: '逐金污师丨成人情趣甄选好物',
	      path: currentPage.route + `?id=${this.id}&share=${this.share}` //后面是路径上要传递的参数
	    }
	  },
  methods: {
    submit() {
      var _this = this;
      if ('' == _this.oldPassword) {
        uni.showToast({
          title: '旧密码不能为空',
          icon: 'error',
          duration: 500
        });
        return;
      }
      if ('' == _this.newPassword1) {
        uni.showToast({
          title: '新密码不能为空',
          icon: 'error',
          duration: 500
        });
        return;
      }
      if ('' == _this.newPassword2) {
        uni.showToast({
          title: '确认密码不能为空',
          icon: 'error',
          duration: 500
        });
        return;
      }
      if (_this.newPassword2 != _this.newPassword1) {
        uni.showToast({
          title: '两次密码不一致',
          icon: 'error',
          duration: 500
        });
        return;
      }
      request({
        url: '/system/user/profile/updatePwd',
        method: "PUT",
        header: {
          'Authorization': uni.getStorageSync('token'), //自定义请求头信息
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: {
          "oldPassword": _this.oldPassword,
          "newPassword": _this.newPassword1 // 当value没有值的时候，默认发送的请求也不传递key
        },
      }).then(res => {
        if (res.code == 500) {
          uni.showToast({
            title: '修改失败',
            icon: 'error',
            duration: 1000
          });
          _this.tips = res.msg;
        } else if (res.code == 401) {
          uni.showToast({
            title: '请先登录',
            icon: 'error',
            duration: 1000
          });
        } else if (res.code == 200) {
          uni.clearStorageSync("token")
          uni.showToast({
            title: '修改成功,请重新登录',
            icon: 'success',
            duration: 1000
          });
          setTimeout(function () {
            uni.navigateTo({
              url: '/pages/login/login'
            })
          }, 1000)
        } else {
          uni.showToast({
            title: '未知异常',
            icon: 'error',
            duration: 1000
          });
        }
      })
    }
  }
}
</script>

<style>
#content {
  background-color: #f5f5f5;
  height: 100%;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
}

.item_area {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 180rpx;
}

.item_view {
  height: 150rpx;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

.input_tips {
  font-size: 32rpx;
  margin-left: 20rpx;
  font-weight: 500;
}

.input_view {
  background-color: white;
  width: 700rpx;
  height: 100rpx;
  border-radius: 10rpx;
  font-size: 30rpx;
}

.input_txt {
  padding-left: 20rpx;
  line-height: 100rpx;
  height: 100rpx;
  font-size: 30rpx;
  color: #b4b4b4;
}

.submit {
  width: 640rpx;
  height: 92rpx;
  border-radius: 46rpx;
  font-size: 36rpx;
  background-image: linear-gradient(to right, #fdd706, #fdb932);
}
</style>
